<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('著作列表')"/>
    <style>

        element.style {
        }
        .select-list li p, .select-list li label:not(.radio-box) {
            float: left;
            width: 80px;
            margin: 5px 5px 5px 0px;
            text-align: right;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label style="width: 80px">著作名称：</label>
                            <input type="text" name="writtingsName"/>
                        </li>

                        <li class="select-time">
                            <label style="width: 80px">出版年月：</label>
                            <input type="text" class="time-input " id="startTime" placeholder="开始时间"
                                   name="params[beginPressTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input " id="endTime" placeholder="结束时间"
                                   name="params[endPressTime]"/>
                        </li>
                        <li>
                            <label style="width: 80px">书号：</label>
                            <input type="text" name="isbn"/>
                        </li>
                        <li>
                            <label style="width: 80px">出版社级别：</label>
                            <select name="pressLevel"
                                    th:with="type=${@dict.getType('press_level')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 80px">申报单位：</label>
                            <select name="reportUnitId" id="reportUnitId"
                                    th:with="type=${@dept.getUnit()}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.deptName}"
                                        th:value="${dict.deptId}"></option>
                            </select>
                        </li>
                        <li class="select-time">
                            <label style="width: 80px">申报时间：</label>
                            <input type="text" class="time-input " id="startTime1" placeholder="开始时间"
                                   name="params[beginReportTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input " id="endTime1" placeholder="结束时间"
                                   name="params[endReportTime]"/>
                        </li>

                        <li>
                            <label style="width: 80px">科室：</label>
                            <select name="departmentId" id="departmentId" >
                                <option th:each="post:${dept}" th:value="${post.deptId}"
                                        th:text="${post.deptName}"></option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 80px">创新激励：</label>
                            <select name="isInnovate"
                                    th:with="type=${@dict.getType('is_innovate')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 80px">高级搜索：</label>
                            <input type="text" name="searchParam" placeholder="名称/作者"/>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:writings:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="edit()"
               shiro:hasPermission="system:writings:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:writings:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:writings:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" style="min-width: 1700px"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:writings:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:writings:remove')}]];
    var showFlag = [[${@permission.hasPermi('system:writings:detail')}]];
    var prefix = ctx + "system/writings";

    $(function () {
        var datas_is_innovate = [[${@dict.getType('is_innovate')}]];
        var datas_press_level = [[${@dict.getType('press_level')}]];
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            detailUrl: prefix + "/detail/{id}",
            modalName: "著作",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'writtingsName',
                    title: '著作名称'
                },
                {
                    field: 'firstAuthor',
                    title: '第一作者'
                },
                {
                    field: 'otherAuthor',
                    title: '其他作者'
                },
                {
                    field: 'firstAuthorUnit',
                    title: '第一作者单位'
                },
                {
                    field: 'words',
                    title: '字数'
                },
                {
                    field: 'press',
                    title: '出版社'
                },
                {
                    field: 'pressTime',
                    title: '出版年月'
                },
                {
                    field: 'isbn',
                    title: '书号'
                },
                {
                    field: 'reportUnit',
                    title: '申报单位'
                },
                {
                    field: 'reportTime',
                    title: '申报时间'
                },
                {
                    field: 'pressLevel',
                    title: '出版社级别',

                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(datas_press_level, item.pressLevel);
                    }
                },
                {
                    field: 'department',
                    title: '科室'
                },
                {
                    field: 'isInnovate',
                    title: '创新激励奖',
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(datas_is_innovate, item.isInnovate);
                    }
                },

                {
                    field: 'gmtTime',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + showFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
                        if (row.auditState == 1 || row.auditState == 4) {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="fujian(\'' + row.id + '\',\'' + row.docType + '\')"><i class="fa fa-edit"></i>附件</a> ');
                            // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="shenhe(\'' + row.id + '\')"><i class="fa fa-edit"></i>提交审核</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);



        $.ajax({
            url: ctx + 'system/dept/getDept',
            async: false,
            type: 'get',
            data: {unit: t},
            success: function (data) {
                var t3 = $("#departmentId").empty();
                t3.append("<option value=''> 所有</option>");
                for (var i = 0; i < data.length; i++) {
                    t3.append("<option value='" + data[i].deptId + "'>" + data[i].deptName + "</option>");
                }
            }
        })

    });
</script>
<script type="text/javascript">
    function fujian(id, docType) {
        var url = ctx + "system/appendix/" + id + "/" + docType;
        var options = {
            title: table.options.modalName + "附件",
            width: 800,
            height: 750,
            url: url,
            skin: 'layui-layer-gray',
            btn: ['关闭'],
            yes: function (index, layero) {
                layer.close(index);
            }
        };
        $.modal.openOptions(options);
        // $.modal.open("附件管理" + table.options.modalName, url)
    }


    function shenhe(id) {
        var url = ctx + "system/writings/applyAudit";
        $.operate.post(url, {"id": id});
    }


    function edit() {
        var column = $.table.selectColumns('auditState');
        if (column == 2 || column == 3) {

            $.modal.alert('已提交审核或审核通过不允许修改', modal_status.FAIL);
            return
        }

        $.operate.edit()
    }

    $("#reportUnitId").change(function () {
        var t = $("#reportUnitId").val();
        if (t == '') {
            return;
        }

        $.ajax({
            url: ctx + 'system/dept/getDept',
            async: false,
            type: 'get',
            data: {unit: t},
            success: function (data) {
                var t3 = $("#departmentId").empty();
                t3.append("<option value=''> 所有</option>");
                for (var i = 0; i < data.length; i++) {
                    t3.append("<option value='" + data[i].deptId + "'>" + data[i].deptName + "</option>");
                }
            }
        })
    });
</script>
</script>

/body>
< /html>